
/*   RolGPS Project
 * 
 *   Copyright (C) 2009 Pablo Alejandro Costesich <rhfixer@gmail.com>
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */
package org.rolgps.libedb.engine.sqlite3.zentus;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.rolgps.libedb.container.DataResult;
import org.rolgps.libedb.exception.DuplicateTableException;
import org.rolgps.libedb.exception.QueryException;
import org.rolgps.libedb.exception.UnknownTableException;
import org.rolgps.libedb.standard.Database;
import org.rolgps.libedb.standard.Manager;
import org.rolgps.libedb.standard.Table;

/**
 *
 * @author xeph
 */
public class ManagerCore extends EngineCore implements Manager {

    private static final String MANAGERNAME = "Sqlite 3 Zentus";
    private static final String VERSION = "0.1.0-RC";
    private List <Table> tables = new ArrayList();
    Database database = null;
    
    public void dumpSQL(String state) {
        /*
         * Esta implementación sirve para devolver mensajes de error y la
         * creación de consultas, no las ejecuta. No devuelve un String
         * porque lo imprime por la salida estándar.
         * 
         * In other words, you should use this to check how much your 
         * queries and my engine suck.
         */
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public ManagerCore(Database database){
        this.database = database;
        this.tables = getTables();
        
    }
    
    
    public void importSQL(StringBuffer sql) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void addTable(Table table) throws DuplicateTableException {
        for(Table existingTable : tables){
            if(existingTable.getName().equals(table.getName())){
                throw new DuplicateTableException(
                        "The table "+
                        table.getName()+
                        " already exists in " + MANAGERNAME + 
                        " (Version " + VERSION +
                        ") Manager.");
            }
        }
        tables.add(table);
    }

    public void install() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void uninstall() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void removeTable(Table table) throws UnknownTableException {
        if(tables.isEmpty()){
            throw new UnknownTableException("I can't find "+table.getName()+
                    ".");
        }else if(tables.indexOf(table)>-1){
            tables.remove(table);
        }
    }

    public String getManagerVersion() {
        return VERSION;
    }

    public String getManagerName() {
        return MANAGERNAME;
    }

    public void alterTable(Table table, String alterationString) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void addUser(String name) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void deleteUser(String name) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String[] getUsers() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void renameUser(String oldName, String newName) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setOwner(String ownerName) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getOwnerId(String ownerName) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public List<Table> getTables() {
        List result=null;
        try {
            DataResult[] dbTables = database.executeQuery("SELECT * FROM infotables;");
        } catch (QueryException ex) {
            Logger.getLogger(ManagerCore.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }

    public List<Table> getTablesByOwnerName(String ownerName) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public List<Table> getTablesByOwnerId(int ownerId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    
}
